Skip to content

fix(message-db): reconnect stale pooled connections dropped by the se…#3603

Open
kiku98 wants to merge 1 commit into
postalserver:mainfrom
kiku98:fix/messagedb-stale-connection-pool
Open

fix(message-db): reconnect stale pooled connections dropped by the se…#3603
kiku98 wants to merge 1 commit into
postalserver:mainfrom
kiku98:fix/messagedb-stale-connection-pool

Conversation

@kiku98

@kiku98 kiku98 commented Jul 13, 2026

Copy link
Copy Markdown

Problem
The MessageDB connection pool hands out pooled Mysql2::Client connections without checking they're still alive. A connection parked in the pool during a quiet period is closed server-side once it idles past MySQL's wait_timeout; the next query on it raises Mysql2::Error: The client was disconnected by the server because of inactivity. The pool's reconnect guard only matched /(lost connection|gone away|not connected)/i, so this error was re-raised instead of triggering a reconnect — aborting message processing and leaving queued messages stuck.

Fix
Ping each pooled connection on checkout; discard and replace it if the server has already closed it.
Broaden the dead-connection pattern to also match the inactivity / server-disconnect wording, as defence-in-depth for connections that die mid-block.

…rver

Pooled Mysql2::Client connections were handed out without verifying
they were still alive. A connection parked in the pool during a quiet
period could be closed server-side once it idled past `wait_timeout`,
and the next query on it raised "disconnected by the server because of
inactivity". This error was not matched by the pool's reconnect guard,
so it propagated up, aborted message processing and left queued
messages stuck.

- Ping each pooled connection on checkout; discard and replace it if
  the server has already closed it.
- Broaden the dead-connection pattern to also match the inactivity /
  server-disconnect wording as defence-in-depth for connections that
  die mid-block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants